package com.wkl.yuyue.utils;

import com.wkl.yuyue.entity.User;
import com.wkl.yuyue.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class passwordService {
    @Autowired
    private IUserService iUserService;
    public static void validate(User sysUser) {
        Authentication authentication = AuthenticationContextHolder.getUserNamePasswordInfo();
        String inputPassword = authentication.getCredentials().toString();
        String username = authentication.getName();
        if(!matchPassword(inputPassword,sysUser.getPassword())){
            throw new RuntimeException("密码错误");
        }
    }


    private static boolean matchPassword(String inputPassword, String password) {
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        return passwordEncoder.matches(inputPassword,password);
    }
}
